package com.loop.netty.http;

import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.http.HttpServerCodec;

/**
 * @author zhangxiaolu
 * @since 2023-09-12 22:20
 */
public class HttpServerInitializer extends ChannelInitializer<SocketChannel> {
    @Override
    protected void initChannel(SocketChannel ch) throws Exception {
        // 向管道加入处理器

        // 得到管道
        ChannelPipeline pipeline = ch.pipeline();
        // 加入一个netty提供的HttpServerCodec codec => [coder - decoder]
        // HttpServerCodec 是一个netty提供的编解码器
        pipeline.addLast("MyHttpServerCodec", new HttpServerCodec());
        // 加入自定义的处理器
        pipeline.addLast("MyHttpServerHandler", new HttpServerHandler());
    }
}
